with Parse_Args;            use Parse_Args;
with lexer;                 use lexer;
with tokens;                use tokens;
with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Surface is
   F            : File_Type;
   in_file_name : Unbounded_String;
   AP           : Argument_Parser;
   The_Lexer    : lexer.Lexer_Type;
   The_Token    : tokens.Token_Type;
begin
   AP.Add_Option
     (Make_Boolean_Option (False), "help", 'h',
      Usage => "Display this help text");
   AP.Add_Option
     (Make_Boolean_Option (False), "compile", 'c',
      Usage => "Compile only, no linking");
   AP.Add_Option
     (Make_Boolean_Option (False), "check", 'C', Usage => "Check the file");
   AP.Append_Positional (Make_String_Option ("FILE"), "FILE");
   AP.Set_Prologue
     ("The surface interpreter. visit https://notabug.org/SouperZ/surface-lang for the source");

   AP.Parse_Command_Line;

   if AP.Parse_Success then
      if AP.Boolean_Value ("help") then
         AP.Usage;
      else

         Open (F, In_File, Ap.String_Value ("FILE"));
         while not End_Of_File (F) loop
            The_Lexer := Lexer.New_Lexer ( To_Unbounded_String (Get_Line (F)));
            loop
               The_Token := lexer.Next_Token (The_Lexer);
               exit when The_Token.Kind = tokens.EOF;
               Put_Line
                 ("{Kind:" & The_Token.Kind'Image & " Literal:" &
                  To_String (The_Token.Literal) & "}");
            end loop;
         end loop;
         Close (F);
      end if;
   else
      Put ("Error while parsing command-line arguments: ");
      Put_Line (AP.Parse_Message);
   end if;
exception
   when Name_Error =>
      Put_Line ("...Name_Error...");

end Surface;
